/**
 * 系统设置相关API
 */
import request from '@/utils/request';

/**
 * 获取系统设置
 * @param {string} group - 设置分组
 */
export function getSettings(group) {
  return request.get('/api/settings', { params: { group } });
}

/**
 * 更新系统设置
 * @param {Object} settings - 设置信息
 */
export function updateSettings(settings) {
  return request.put('/api/settings/batch', settings);
}

/**
 * 删除设置
 * @param {number} id - 设置ID
 */
export function deleteSetting(id) {
  return request.delete(`/api/settings/${id}`);
}

/**
 * 获取聊天机器人设置
 */
export function getChatbotSettings() {
  return request.get('/api/settings/chatbot');
}

/**
 * 更新聊天机器人设置
 * @param {Object} settings - 设置数据
 */
export function updateChatbotSettings(settings) {
  return request.put('/api/settings/chatbot', settings);
}

/**
 * 重置聊天机器人设置
 */
export function resetChatbotSettings() {
  return request.post('/api/settings/chatbot/reset');
}

/**
 * 获取AI模型列表
 */
export function getAIModels() {
  return request.get('/api/ai/models');
}

/**
 * 测试AI模型
 * @param {string} modelId - 模型ID
 * @param {string} prompt - 测试文本
 */
export function testAIModel(modelId, prompt) {
  return request.post('/api/ai/models/test', { modelId, prompt });
}

/**
 * 获取知识库列表
 * @param {Object} params - 查询参数
 */
export function getKnowledgeBases(params) {
  return request.get('/api/knowledge-bases', { params });
}

/**
 * 创建知识库
 * @param {Object} knowledgeBase - 知识库信息
 */
export function createKnowledgeBase(knowledgeBase) {
  return request.post('/api/knowledge-bases', knowledgeBase);
}

/**
 * 更新知识库
 * @param {string} id - 知识库ID
 * @param {Object} knowledgeBase - 知识库信息
 */
export function updateKnowledgeBase(id, knowledgeBase) {
  return request.put(`/api/knowledge-bases/${id}`, knowledgeBase);
}

/**
 * 删除知识库
 * @param {string} id - 知识库ID
 */
export function deleteKnowledgeBase(id) {
  return request.delete(`/api/knowledge-bases/${id}`);
}

/**
 * 导入知识库文档
 * @param {string} id - 知识库ID
 * @param {FormData} formData - 文档数据
 */
export function importKnowledgeBaseDocument(id, formData) {
  return request.post(`/api/knowledge-bases/${id}/documents/import`, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

/**
 * 获取知识库列表
 * @param {Object} params 查询参数
 * @returns {Promise} 请求Promise
 */
export const getKnowledgeList = (params) => {
    return request.get('/api/knowledge', { params });
};

/**
 * 添加知识库条目
 * @param {Object} data 知识库数据
 * @returns {Promise} 请求Promise
 */
export const addKnowledgeItem = (data) => {
    return request.post('/api/knowledge', data);
};

/**
 * 更新知识库条目
 * @param {Object} data 知识库数据
 * @returns {Promise} 请求Promise
 */
export const updateKnowledgeItem = (data) => {
    return request.put('/api/knowledge', data);
};

/**
 * 删除知识库条目
 * @param {number} id 知识库ID
 * @returns {Promise} 请求Promise
 */
export const deleteKnowledgeItem = (id) => {
    return request.delete(`/api/knowledge/${id}`);
};

/**
 * 批量导入知识库
 * @param {FormData} formData 包含导入文件的表单数据
 * @returns {Promise} 请求Promise
 */
export const importKnowledge = (formData) => {
    return request.post('/api/knowledge/import', formData);
};

export default {
    getSettings,
    updateSettings,
    deleteSetting,
    getChatbotSettings,
    updateChatbotSettings,
    resetChatbotSettings,
    getAIModels,
    testAIModel,
    getKnowledgeBases,
    createKnowledgeBase,
    updateKnowledgeBase,
    deleteKnowledgeBase,
    importKnowledgeBaseDocument,
    getKnowledgeList,
    addKnowledgeItem,
    updateKnowledgeItem,
    deleteKnowledgeItem,
    importKnowledge
}; 